﻿using Farming.Domain;
using Farming.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Farming.Repositories
{
    public class AdminRepository : Repository<Admin>
    {
        private readonly FarmingDbContext db;
        public AdminRepository(FarmingDbContext db) : base(db)
        {
            this.db = db;
        }
        public override async Task<int> InSertAsync(Admin entity)
        {
            var user = db.Admins.FirstOrDefault(t => t.UserName == entity.UserName);
            if (user!= null)
            {
                throw new Exception("用户名已存在");
            }
            return await base.InSertAsync(entity);
        }
    }
}
